package bread;

public class Producer extends Thread {
    @Override
    public void run() {
        while (true) {
            synchronized (Bread.lock) {
                if (Bread.count == 0) {
                    break;
                } else {
                    if (!Bread.flag) {
                        System.out.println("正在生产面包");
                        Bread.flag = true;
                        Bread.lock.notify();
                    } else {
                        //有包子,则不生产
                        //进入等待状态
                        try {
                            Bread.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);

                        }
                    }
                }
            }
        }
    }
}